import axios from "axios"
import store from "@/store";

const instance = axios.create({
    baseURL:"http://www.wsit.cn:8068/shopdemo/public/index.php/addons/xshop",
    timeout:3000
})

instance.interceptors.request.use(config=>{
        let token = store.state.token;
        if(token){
            config.headers["Xshop-Token"] = token;
        }
    return config;
},err=>{
    console.log(err.message);
})

instance.interceptors.response.use(response=>{
    return response;
},err=>{
    if(err.response.status){
        switch(err.response.status){
            case 401:
			    alert("未授权请稍后尝试");
			    break;
			
			case 403:
                alert("禁止访问");
                break;
			
			case 404:
                alert("资源不存在");
                break;
			
		    default:alert("error");
		}
		return Promise.reject(error.response)
    }
})


export default instance